package com.study.test2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class classForName1 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<?> userCls = Class.forName("com.study.test2.User");

        Method[] methods = userCls.getMethods();
        Arrays.stream(methods).forEach(System.out::println);

        User u1 = (User)userCls.newInstance();
        u1.SayHello();

        User u2 = (User)userCls.getDeclaredConstructor().newInstance();
        u2.SayHello();
    }
}
